package com.esfak47.mediafetcher.core.constants;

import com.esfak47.common.lang.CodeMessageProvider;

import java.io.File;

/**
 * @author tony
 * @date 2018/5/3
 */
public interface Constants {
    String BASE_DIR = System.getProperty("app.home", System.getProperty("user.dir"));
    String PLUGINS_DIR = System.getProperty("plugins.path", getPath("plugins"));
    String MODULES_DIR = System.getProperty("modules.path", getPath("modules"));
    String SEVER_PORT = System.getProperty("server.port", "8080");
    boolean USE_PROXY = Boolean.valueOf(System.getProperty("server.proxy.enable", "true"));
    Integer PROXY_PORT = Integer.valueOf(System.getProperty("server.proxy.port", "1089"));
    String LOG_DIR = getPath("logs");
    String TEMP_DIR = getPath("tmp");

    static String getPath(String... s) {
        if (s == null || s.length == 0) {
            return BASE_DIR;
        } else {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(BASE_DIR);
            for (String string : s) {
                stringBuilder.append(File.separator);
                stringBuilder.append(string);
            }
            return stringBuilder.toString();
        }
    }

    public enum JobSubjects {
        log,
        finish,
        start,
        cancel,
        delete,
        error
    }

    public enum MediaSubjects {
        fetched
    }

    public enum ServerOptCode implements CodeMessageProvider {
        createJobFailed(20001, "创建任务失败"),
        submitJobFailed(20002, "提交任务失败");

        private final int code;
        private final String message;

        ServerOptCode(int code, String message) {
            this.code = code;
            this.message = message;
        }

        @Override
        public int getCode() {
            return code;
        }

        @Override
        public String getMessage() {
            return message;
        }
    }
}
